﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Gedea.Core
{
    public static class CacheManager
    {
        public static void Add<T>(T value)
        {
            AppDomain.CurrentDomain.SetData(GetKey(value), value);
        }

        public static bool IsCached<T>(T value)
        {
            return AppDomain.CurrentDomain.GetData(GetKey(value)) != null;
        }

        public static T Get<T>(T value)
        {
            return (T)AppDomain.CurrentDomain.GetData(GetKey(value));
        }

        public static void Remove<T>(T value)
        {
            AppDomain.CurrentDomain.SetData(GetKey(value), null);
        }

        public static void Refresh<T>(T value)
        {
            throw new NotImplementedException();
        }

        private static string GetKey<T>(T value)
        {
            string res = value.ToString().Split('.').Last().Replace(']', ' ').Trim();
            return value.ToString().Contains("List") || value.ToString().Contains("Enumerable") ? res + "Collection" : res;
        }
    }
}
